// 生成未来7天的可用时间段
function generateAvailableTimes() {
  const availableTimes = [];
  const today = new Date();
  
  // 时间段配置
  const timeSlots = [
    '08:30-09:30',
    '09:30-10:30', 
    '10:30-11:30',
    '14:00-15:00',
    '15:00-16:00',
    '16:00-17:00'
  ];
  
  // 生成未来7天的可用时间
  for (let i = 0; i < 7; i++) {
    const date = new Date(today);
    date.setDate(today.getDate() + i);
    
    const dateStr = date.toISOString().split('T')[0]; // YYYY-MM-DD格式
    
    const daySchedule = {
      date: dateStr,
      timeSlots: timeSlots.map(time => ({
        time: time,
        isAvailable: true,
        patientId: null
      }))
    };
    
    availableTimes.push(daySchedule);
  }
  
  return availableTimes;
}

// 获取下一个可用时间段
function getNextAvailableTime(availableTimes) {
  for (const day of availableTimes) {
    for (const slot of day.timeSlots) {
      if (slot.isAvailable) {
        const date = new Date(day.date);
        const month = date.getMonth() + 1;
        const dayOfMonth = date.getDate();
        const time = slot.time;
        
        return `${month}月${dayOfMonth}日 ${time}`;
      }
    }
  }
  return '暂无可用时间';
}

// 预约时间段
function bookTimeSlot(availableTimes, date, time, patientId) {
  for (const day of availableTimes) {
    if (day.date === date) {
      for (const slot of day.timeSlots) {
        if (slot.time === time && slot.isAvailable) {
          slot.isAvailable = false;
          slot.patientId = patientId;
          return true;
        }
      }
    }
  }
  return false;
}

module.exports = {
  generateAvailableTimes,
  getNextAvailableTime,
  bookTimeSlot
}; 